//
//  RCMemeberCardCell.m
//  RocketProject
//
//  Created by chen jiedan on 13-8-22.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMemeberCardCell.h"
#import "CommonDefines.h"
#import "UIColor-Expanded.h"
#import "UIImageView+WebCache.h"

#define kLineImageFile           @"image_line_type3.png"

@implementation RCMemeberCardCell{
    UILabel *_orderLabel;
    UILabel *_headLabel;
    UILabel *_description;
    
    UIImageView *_rightImg;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self createPlaceHolder];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void) createPlaceHolder
{
    UIImageView *orderImg = [[UIImageView alloc] initWithFrame:CGRectMake(18, 18, 15, 14)];
    orderImg.image = [UIImage imageNamed:@"image_member_dot_bg.png"];
    [self.contentView addSubview:orderImg];
    [orderImg release];
    
    _orderLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 14, 15)];
    _orderLabel.text = @"1";
    [_orderLabel setTextColor:[UIColor whiteColor]];
    [_orderLabel setFont:[UIFont systemFontOfSize:12]];
    [_orderLabel setBackgroundColor:[UIColor clearColor]];
    [_orderLabel setTextAlignment:NSTextAlignmentCenter];
    [orderImg addSubview:_orderLabel];
    [_orderLabel release];
    
    _headLabel = [[UILabel alloc] initWithFrame:CGRectMake(35, 18, 100, 15)];
    _headLabel.textColor = [UIColor orangeColor];
    _headLabel.backgroundColor = [UIColor clearColor];
    _headLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:_headLabel];
    [_headLabel release];
    
    _description = [[UILabel alloc] initWithFrame:CGRectMake(40, 35, 220, 40)];
    _description.textColor = kNormalTextColor;
    _description.backgroundColor = [UIColor clearColor];
    _description.font = [UIFont fontWithName:kFontNameHelvetica size:13];
    _description.numberOfLines = 0;
    [self.contentView addSubview:_description];
    [_description release];
    
    _rightImg = [[UIImageView alloc] initWithFrame:CGRectMake(275, 20, 30, 35)];
    [self.contentView addSubview:_rightImg];
    [_rightImg release];
}

+ (CGFloat) cellHeightFor:(RCCardTypeIntroduce *)dataModel
{
     UILabel *description = [[[UILabel alloc] initWithFrame:CGRectMake(40, 35, 220, 40)] autorelease];
    description.font = [UIFont fontWithName:kFontNameHelvetica size:13];
    description.numberOfLines = 0;
    description.text = dataModel.content;
    [description sizeToFit];
    return description.frame.origin.y + description.frame.size.height;
    
}
- (void) bindData:(RCCardTypeIntroduce *)dataModel
{
    TakeCardType type = dataModel.type;
    _headLabel.text = dataModel.title;
    _description.text = dataModel.content;
    [_description sizeToFit];
    
    switch (type) {
        case TakeCardType_SelfTake:
        {
            _orderLabel.text = @"1";
        
            UIImage *img = [UIImage imageNamed:@"image_member_takeCard_01"];
            _rightImg.image = img;
            CGRect frame = _rightImg.frame;
            frame.size.height = img.size.height; frame.size.width = img.size.width;
            _rightImg.frame = frame;
            break;
        }
        case TakeCardType_WebTake:
        {
            _orderLabel.text = @"2";
         
            UIImage *img = [UIImage imageNamed:@"image_member_takeCard_02"];
            _rightImg.image = img;
            CGRect frame = _rightImg.frame;
            frame.size.height = img.size.height; frame.size.width = img.size.width;
            _rightImg.frame = frame;
            break;
        }
        case TakeCardType_PhoneTake:
        {
            _orderLabel.text = @"3";
            UIImage *img = [UIImage imageNamed:@"image_member_takeCard_03"];
            _rightImg.image = img;
            CGRect frame = _rightImg.frame;
            frame.size.height = img.size.height; frame.size.width = img.size.width;
            _rightImg.frame = frame;
            break;
        }
        default:
            break;
    }
}

@end



@implementation RCMemeberCardTypeCell{
    UIImageView *_leftImg;
    UILabel     *_headLabel;
    UILabel     *_subTitle;
    UILabel     *_description;
    
    UIButton    *_btn;
}

@synthesize delegate = _delegate;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self createPlaceHolder];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}


- (void) createPlaceHolder
{
    UIImageView *_lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self.contentView addSubview:_lineImageView];
    [_lineImageView release];
    
    
    _leftImg = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 0, 0)];
    [self.contentView addSubview:_leftImg];
    [_leftImg release];
    
    _headLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 20, 110, 20)];
    [self.contentView addSubview:_headLabel];
    [_headLabel setBackgroundColor:[UIColor clearColor]];
    _headLabel.textColor = [UIColor orangeColor];
    [_headLabel release];
    
    
    _subTitle = [[UILabel alloc] initWithFrame:CGRectMake(210, 20, 100, 20)];
    [self.contentView addSubview:_subTitle];
    _subTitle.textAlignment = NSTextAlignmentLeft;
    _subTitle.font = [UIFont fontWithName:kFontNameHelvetica size:13];
    _subTitle.textColor = kNormalTextColor;
    [_subTitle setBackgroundColor:[UIColor clearColor]];
    [_subTitle release];
    
    _description = [[UILabel alloc] initWithFrame:CGRectMake(100, 40, 140, 40)];
    [self.contentView addSubview:_description];
    _description.numberOfLines = 0;
    _description.font = [UIFont fontWithName:kFontNameHelvetica size:13];
    _description.textColor = kNormalTextColor;
    _description.backgroundColor = [UIColor clearColor];
    [_description release];
    
    _btn = [[UIButton alloc] initWithFrame:CGRectMake(260, 45, 50, 20)];
    [self.contentView addSubview:_btn];
    [_btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    [_btn release];
}

+ (CGFloat) cellHeightFor:(RCCardTypeInfo *)info
{
    CGFloat height;
    UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(100, 40, 140, 40)];
    description.font = [UIFont fontWithName:kFontNameHelvetica size:13];
    description.numberOfLines = 0;
    description.text = info.content;
    height = description.frame.origin.y + description.frame.size.height;
    [description release];
    
    return height;
    
}
- (void) bindData:(RCCardTypeInfo *)info
{
    UIImage *img = [UIImage imageNamed:@"image_member_cardType01"];
    [_leftImg setImageWithURL:[NSURL URLWithString:info.picUrl] placeholderImage:img];
//    _leftImg.image = img;
    CGRect frame = _leftImg.frame;
    frame.size.width = img.size.width; frame.size.height = img.size.height;
    _leftImg.frame = frame;
    
    _headLabel.text = [NSString stringWithFormat:@"%@*",info.title];
    _subTitle.text = info.subtitle;
    _description.text = info.content;
    [_description sizeToFit];
    
    [_btn setBackgroundImage:[UIImage imageNamed:@"image_member_takeBtn"] forState:UIControlStateNormal];
    //使用tag来标识哪种类型的 卡 被点击了
    _btn.tag = 100;
}

- (void) btnClick
{
    NSInteger tag = _btn.tag;
    
    if ([_delegate respondsToSelector:@selector(clickToTakeCard:)]) {
        [_delegate clickToTakeCard:tag];
    }
}
@end
